﻿@namespace Blazorise.Docs.Docs.Examples

<DataGrid TItem="Employee"
          Data="@employeeList"
          NavigationMode="DataGridNavigationMode.Cell"
          @bind-Selectedcell="@selectedCell"
          Responsive>
    <DataGridMultiSelectColumn Width="30px"></DataGridMultiSelectColumn>
    <DataGridCommandColumn />
    <DataGridColumn Field="@nameof(Employee.Id)" Caption="#" Sortable="false" />
    <DataGridColumn Field="@nameof(Employee.FirstName)" Caption="First Name" Editable />
    <DataGridColumn Field="@nameof(Employee.LastName)" Caption="Last Name" Editable />
    <DataGridColumn Field="@nameof(Employee.Email)" Caption="Email" Editable />
    <DataGridColumn Field="@nameof(Employee.Salary)" Caption="Salary" DisplayFormat="{0:C}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo("fr-FR")" Editable>
        <EditTemplate>
            <NumericEdit TValue="decimal" Value="@((decimal)context.CellValue)" ValueChanged="@( v => context.CellValue = v)" />
        </EditTemplate>
    </DataGridColumn>
</DataGrid>

<Row>
    <Column>
        <Card>
            <CardHeader>
                <CardTitle>Selected Cell</CardTitle>
            </CardHeader>
            <CardBody>
                <Fields>
                    <Field>
                        <FieldLabel>Row Index</FieldLabel>
                        <FieldBody>
                            <TextEdit ReadOnly Text="@selectedCell?.RowIndex.ToString()"></TextEdit>
                        </FieldBody>
                    </Field>
                    <Field>
                        <FieldLabel>Field</FieldLabel>
                        <FieldBody>
                            <TextEdit ReadOnly Text="@selectedCell?.ColumnInfo?.Field"></TextEdit>
                        </FieldBody>
                    </Field>
                    <Field>
                        <FieldLabel>Value</FieldLabel>
                        <TextEdit ReadOnly Text="@selectedCell?.Column?.FormatDisplayValue(selectedCell?.Item)"></TextEdit>
                    </Field>
                </Fields>
            </CardBody>
        </Card>
    </Column>
</Row>

@code {
    [Inject]
    public EmployeeData EmployeeData { get; set; }
    private List<Employee> employeeList;
    private DataGridCellInfo<Employee> selectedCell;

    protected override async Task OnInitializedAsync()
    {
        employeeList = await EmployeeData.GetDataAsync();
        await base.OnInitializedAsync();
    }
}